import { defineConfig, loadEnv } from 'vite'
import { resolve } from "path"
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig(({ mode, command }) => {

  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_ENV } = env
  return {
    base: VITE_APP_ENV === 'production' ? '/' : '/',
    plugins: [
      vue(),
      AutoImport({
        // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
        imports: ['vue'],
      }),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    root: 'src',
    build: {
      outDir: '../dist',
      rollupOptions: {
        input: {
          detail: resolve(__dirname, 'src/detail/index.html'),
          approve: resolve(__dirname, 'src/approve/index.html')
        }
      }
    },
    define: {
      'process.env': process.env,
    },
  }
})


